/**
 * user edit
 */
layui.use(['form', 'tableSelect'], function () {
    var form = layui.form,
        layer = layui.layer,
        tableSelect = layui.tableSelect,
        $ = layui.jquery;

    let shipId="";
    let u=localStorage.getItem("ADMIN_LOGIN");
    let loginU={};
    if(u==undefined){layer.msg('请登录', {icon: 1, time: 500},function () {window.location = 'page/login.html';});}else{loginU=decryptLocalStorage(u);}
    let _data=localStorage.getItem("sailastvClientData");
    let viewData=undefined;
    if(_data!=undefined){
        viewData=decryptLocalStorage(_data,loginU.token);
        $("#userKey").val(viewData.userKey);
        $("#remark").val(viewData.remark);
    }

    //监听提交
    form.on('submit(saveBtn)', function (data) {
        let params=data.field;
        params.token=loginU.token;
        //添加
        if(viewData==undefined){
            request.add('sailastvClient',JSON.stringify(params),function(result){
                if(result.code==0){
                    layer.msg('保存成功', {
                        icon: 1,
                        time: 500
                    },function () {
                        // 关闭弹出层
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    });

                }else{
                    layer.msg(result.msg || '保存失败', {
                        icon: 2,
                        time: 2000
                    });
                }
            });
        }
        //修改
        else{
            params.sailastvClientId=viewData.sailastvClientId;
            request.update('sailastvClient',JSON.stringify(params),function(result){
                if(result.code==0){
                    layer.msg('保存成功', {
                        icon: 1,
                        time: 500
                    },function () {
                        // 关闭弹出层
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    });

                }else{
                    layer.msg(result.msg || '保存失败', {
                        icon: 2,
                        time: 2000
                    });
                }
            });
        }

        return false;
    });


});